home *** CD-ROM | disk | FTP | other *** search
/ PD Collection CD 1 / PD Collection CD 1.iso / textual / tex / files / !tex / TeXsource / commontex / c / io < prev    next >
Encoding:
Text File  |  1988-04-08  |  2.3 KB  |  143 lines

  1. /*
  2.  *    Copyright 1986, 1987 Pat Joseph Monardo. All rights reserved.
  3.  *    Copying of this file is granted according to the provisions 
  4.  *    specified in the file COPYING which must accompany this file.
  5.  */
  6.  
  7.  
  8. /*
  9.  *        io.c
  10.  */
  11.  
  12. #include "tex.h"
  13. #include "char.h"
  14. #include "str.h"
  15. #include "tokenstack.h"
  16. #include "print.h"
  17. #include "file.h"
  18. #include "io.h"
  19.  
  20. int        last;
  21. ascii    buffer[BUF_SIZE];
  22. int        first;
  23. int        max_buf_stack;
  24.  
  25. FILE *
  26. a_open_in ()
  27. {
  28.     if (test_access(READ_ACCESS, INPUT_FILE_PATH))
  29.         return (fopen(name_of_file, "r"));
  30.     return NULL;
  31. }
  32.  
  33. FILE *
  34. a_open_out ()
  35. {
  36.     if (test_access(WRITE_ACCESS, NO_FILE_PATH))
  37.         return (fopen(name_of_file, "w"));
  38.     return NULL;
  39. }
  40.  
  41. FILE *
  42. b_open_in ()
  43. {
  44.     if (test_access(READ_ACCESS, FONT_FILE_PATH))
  45.         return (fopen(name_of_file, "r"));
  46.     return NULL;
  47. }
  48.  
  49. FILE *
  50. b_open_out ()
  51. {
  52.     if (test_access(WRITE_ACCESS, NO_FILE_PATH))
  53.         return (fopen(name_of_file, "w"));
  54.     return NULL;
  55. }
  56.  
  57. FILE *
  58. w_open_in ()
  59. {
  60.     if (test_access(READ_ACCESS, FORMAT_FILE_PATH))
  61.         return (fopen(name_of_file, "r"));
  62.     return NULL;
  63. }
  64.  
  65. FILE *
  66. w_open_out ()
  67. {
  68.     if (test_access(WRITE_ACCESS, NO_FILE_PATH))
  69.         return (fopen(name_of_file, "w"));
  70.     return NULL;
  71. }
  72.  
  73. bool 
  74. input_ln (f, bypass_eoln)
  75.     alpha_file    f;
  76.     bool        bypass_eoln;
  77. {
  78.     int            c;
  79.  
  80.     last = first;
  81.     loop {
  82.         c = getc(f);
  83.         if (c == EOLN)
  84.             break;
  85.         if (c == EOF) {
  86.             if (last == first)
  87.                 return FALSE;
  88.             else
  89.                 break;
  90.         }
  91.         if (last > max_buf_stack) {
  92.             max_buf_stack = last + 1;
  93.             if (max_buf_stack == BUF_SIZE - 1)
  94.                 overflow("buffer size", BUF_SIZE);
  95.         }
  96.         buffer[last] = xord[c];
  97.         incr(last);
  98.     }
  99.     loop {
  100.         if (last == first)
  101.             break;    
  102.         else if (buffer[last - 1] != ' ')
  103.             break;
  104.         else decr(last);
  105.     }
  106.     return TRUE;
  107. }
  108.  
  109. term_input ()
  110. {
  111.     int        k;
  112.  
  113.     update_terminal();
  114.     if (!input_ln(term_in, FALSE)) 
  115.         fatal_error("! End of file on the terminal");
  116.     term_offset = 0;
  117.     decr(selector);
  118.     if (last != first)
  119.         for (k = first; k < last; incr(k))
  120.             print_char(buffer[k]);
  121.     print_ln();
  122.     incr(selector);
  123. }
  124.  
  125. bool
  126. init_terminal ()
  127. {
  128.     loop {
  129.         fputs("**", stdout);
  130.         update_terminal();
  131.         if (!input_ln(term_in, FALSE)) {
  132.             puts("\n! End of file on the terminal...why?");
  133.             return FALSE;
  134.         }
  135.         loc = first;
  136.         while (loc < last && buffer[loc] == ' ')
  137.             incr(loc);
  138.         if (loc < last)
  139.             return TRUE;
  140.         puts("Please type the name of your input file.");
  141.     }
  142. }
  143.